package com.easthome.service.impl;

import com.easthome.mapper.CheckGroupMapper;
import com.easthome.mapper.CheckItemMapper;
import com.easthome.mapper.SetMealMapper;
import com.easthome.pojo.CheckGroup;
import com.easthome.pojo.CheckItem;
import com.easthome.pojo.SetMeal;
import com.easthome.service.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetMealServiceImpl implements SetMealService {
    @Autowired
    private SetMealMapper setMealMapper;
    @Autowired
    private CheckGroupMapper checkGroupMapper;
    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * 移动端查询所有套餐
     * @return
     */
    @Override
    public List<SetMeal> querySetMealAll() {
        List<SetMeal> setMeals = setMealMapper.querySetMealAll();
        return setMeals;
    }

    /**
     * 移动端查询所有套餐
     * @return
     */
    @GetMapping("/querySetMealById")
    @Override
    public SetMeal querySetMealById(Integer id) {
        //查询id对性的套餐内容
        SetMeal setMeal = setMealMapper.querySetMealById(id);
        //查询套餐对应的检查组
        List<CheckGroup> checkGroups = checkGroupMapper.queryGroupBySetMealId(id);
        //查询每个检查组对应的检查项
        for (CheckGroup checkGroup : checkGroups) {
           List<CheckItem> checkItems = checkItemMapper.queryCheckItemsByCheckGroupId(checkGroup.getId());
           checkGroup.setCheckItems(checkItems);
        }
        setMeal.setCheckGroups(checkGroups);
        return setMeal;
    }
}
